<?php
class ClientStatistics extends CI_Controller{
	
	public function __construct(){
		parent::__construct();
		$this->load->model('StatisticsModel', 'statistics', TRUE);
	}
	
	public function index(){
		echo "this contain login action from client";
	}
	
	public function get_bill_by_date(){
		
		//get begin date
		if (!isset($_GET['begin_date']) || empty($_GET['begin_date'])){
			$arr = array('status' => 'fail', 'message' => 'error message here 1');
			echo json_encode($arr);
			exit();
		}
		
		$begin_date = $_GET['begin_date'];
		
		//get end date
		if (!isset($_GET['end_date']) || empty($_GET['end_date'])){
			$arr = array('status' => 'fail', 'message' => 'error message here 2');
			echo json_encode($arr);
			exit();
		}
		
		$end_date = $_GET['end_date'];
		
		$bill = $this->statistics->get_bill_by_date($begin_date, $end_date);
		
		if ($bill == false){
			$arr = array('status' => 'success', 'info' => array());
			echo json_encode($arr);
			exit();
		}
		
		$arr = array('status' => 'success', 'info' => $bill);
		echo json_encode($arr);
	}
	
	public function get_bill_description_by_date(){
		//get begin date
		if (!isset($_GET['begin_date']) || empty($_GET['begin_date'])){
			$arr = array('status' => 'fail', 'message' => 'error message here 1');
			echo json_encode($arr);
			exit();
		}
		
		$begin_date = $_GET['begin_date'];
		
		//get end date
		if (!isset($_GET['end_date']) || empty($_GET['end_date'])){
			$arr = array('status' => 'fail', 'message' => 'error message here 2');
			echo json_encode($arr);
			exit();
		}
		
		$end_date = $_GET['end_date'];
		
		$bill_description = $this->statistics->get_bill_description_by_date($begin_date, $end_date);
		
		if ($bill_description == false){
			$arr = array('status' => 'success', 'info' => array());
			echo json_encode($arr);
			exit();
		}
		
		$arr = array('status' => 'success', 'info' => $bill_description);
		echo json_encode($arr);
	}
}